#ifndef DCADATATYPES_H
#define DCADATATYPES_H

/***************************************************************************
				DcaDataTypes.h
                             -------------------
Copyright (c) 2009-2010 
Author: Kishor D. Bhalerao (kishor8dm@gmail.com)
Contributors: 

This file is associated with the Ph.D. dissertation,"ON METHODS FOR EFFICIENT
AND ACCURATE DESIGN AND SIMULATION OF MULTIBODY SYSTEMS", Bhalerao K.D,
Rensselaer Polytechnic Institute, 2010.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1.) Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2.) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

3.) The name of the authors, their employers, or sponsoring organizations may
not be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHORS, THEIR EMPLOYERS, OR SPONSORING ORGANIZATIONS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/

#include "SimTKsimbody.h"
//#include "SimTKsimbody_aux.h"
using namespace SimTK;
//#include "DcaPreprocessor.h" This command is wrong, using this command, the compiler 
// wants to first compile DcaPreprocessor, but in that class, we are using DcaBodyData which is in
// this class and gives error. 
// when we have two classes call each other we should do the following instead of inclue

class DcaPreprocessor; // It shows that we will have a private member with the type of DcaPreprocessor (DcaObj)
class HandleEqs;       // It shows that we will have a private member with the type of HandleEqs (Eqns)


// This structure has two handle equations of motion for the entire system
struct TwoHandleEquations{
	const DcaPreprocessor& DcaObj;
	HandleEqs& Eqns;
	TwoHandleEquations(const DcaPreprocessor& DcaObj,HandleEqs& Eqns):DcaObj(DcaObj),Eqns(Eqns){}
};

struct DcaBodyData{
	// All quantities in this structure are expressed in Mobilizer Basis 
	// for each body and are fixed for the entire course of simulation
	
	// Equations of motion
	Mat66 psi11,psi12,psi21,psi22,SfH1,SfH2;

	// Inertia matrix and its inverse
	Mat33 Iner, iIner;

	// Handle Vectors
	Vec3 cm2H1, cm2H2, BtoCM;
	
	// Id of the body. This corresponds to the SimTK Mobilizer Id
	int Id;
};

// Specific just to project momenta
struct DcaBodyData_projectMom{
	Mat66 psi11, psi12, psi21, psi22;
};

// Structure to store handle equations of motion for composite bodies
struct EomData{
	Mat66 psi11,psi12,psi21,psi22;
	Vec6 psi13,psi23;
};

// Add new joint types here
enum JointType {
  FREEJOINT = 1,
  REVOLUTEJOINT = 2,
  SPHERICALJOINT = 3,
  RIGIDJOINT = 4
};

class ConstraintForce{
public:
	
	ConstraintForce(){FcH1=NULL;FcH2=NULL;}
	~ConstraintForce(){
		if(FcH1!=NULL){
			delete []FcH1;
			delete []FcH2;
		}
	}
	void Init(const int& nBodies){
		this->FcH1 = new Vec6[nBodies-1];
		this->FcH2 = new Vec6[nBodies-1];
	}
	void clear(){
		if(FcH1!=NULL){
			delete []FcH1;delete []FcH2;
			FcH1=FcH2=NULL;
		}		
	}
	Vec6* getFcH1Ptr(){return this->FcH1;}
	Vec6* getFcH2Ptr(){return this->FcH2;}
private:
	Vec6 *FcH1, *FcH2;
};

class AngularAcceleration{
public:
	
	AngularAcceleration(){Ang=NULL;}
	~AngularAcceleration(){if(Ang!=NULL)delete []Ang;}
	void Init(const int& nBodies){Ang = new Vec3[nBodies-1];}
	void clear(){if(Ang!=NULL)delete [] Ang;Ang=NULL;}
	Vec3* getPtr(){return this->Ang;}
private:
	Vec3 *Ang;
};


// Class to store delta v for each handle (Jumps in the spatial velocities of each handle)
class DeltaV{
	public:
		DeltaV(){DvH1=NULL;DvH2=NULL;}
		~DeltaV(){
			if(DvH1!=NULL){
				delete [] DvH1; 
				delete [] DvH2;
			}
		}
		void Init(const int& nBodies){
			DvH1 = new Vec6[nBodies-1];
			DvH2 = new Vec6[nBodies-1];
		}
		void clear(){
			if(DvH1!=NULL){
				delete [] DvH1; 
				delete [] DvH2;
				DvH1 = NULL;
				DvH2 = NULL;
			}
		}
		Vec6* getH1Ptr(){return this->DvH1;}
		Vec6* getH2Ptr(){return this->DvH2;}
	private:
		Vec6 *DvH1, *DvH2;
};

#endif
